package com.android.geotrack;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class TrackDetailsActivity extends Activity
{
	private String title = "";
	private String artist = "";
	private String thumb = "";
	
	@Override
	public void onCreate(Bundle som)
	{
		super.onCreate(som);
		setContentView(R.layout.track_details_view);
		
		Intent i = this.getIntent();
		Bundle b = i.getExtras();
		title = (String) b.get("title");
		artist = (String) b.get("artist");
		thumb = (String) b.get("thumb");
		
		loadTrack();
		
		final Button backButton = (Button) findViewById(R.id.back_button);
		backButton.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {            	
	            	//Intent backIntent = new Intent(TrackDetailsActivity.this, Container.class);
	            	//TrackDetailsActivity.this.startActivity(backIntent);
	            	finish();
	            }
	        });
	}
	
	private void loadTrack()
	{
		TextView titleView = (TextView)findViewById(R.id.track_title);
		titleView.setText(title);
		
		ImageView imageView = (ImageView)findViewById(R.id.track_image);
		URL imageUrl;
		try {
			imageUrl = new URL(thumb);
			Drawable d = Drawable.createFromStream(imageUrl.openStream(), "image.jpg");
			imageView.setImageDrawable(d);
		} catch (MalformedURLException e) {
			Log.e("Exception", e.toString());
		} catch (IOException e) {
			Log.e("Exception", e.toString());
		}
		
		TextView artistView = (TextView)findViewById(R.id.track_artist);
		artistView.setText(artist);
	}

}